const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')

const app = express()

// 配置中间件
// 开放静态资源
app.use('/cuifan/', express.static('./public/'))
  // app.use(express.static('./public/'))

// 配置模板引擎 --> 配置完成后会给res增加一个render方法

// view engine setup
app.engine('html', require('express-art-template'));
app.set('views', path.join(__dirname, 'views'));

// 3.配置body-parser 
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

// 配置session


app.get('/', (req, res) => {
  res.render('index.html', {
    data: req.query
  })
})

app.post('/', (req, res) => {
  console.log(req.body);
})

app.listen(3000, () => {
  console.log('running...');
})